Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Razor completion bugs #6441

Merged

Conversation

allisonchou
Copy link
Contributor

These fixes are both pretty hacky, but I believe we lack reasonable alternatives at the moment.

  1. Fixes bug where all completion item icons are incorrect (notice ushort appears with the snippet icon instead of the keyword icon):
    image

This is because we're deserializing the LSP completion item type returned by Roslyn into a VS Code completion item type. Notice that the CompletionItemKinds on both types are off by one:
image

  1. Fixes [Linux/Mac] Can't get the intellisense for @using on Blazor App  #6199

We technically have the same bug in VS, but since we have snippets available there (snippets are currently unavailable for Razor in VS Code), we still get using in the completion list (screenshot below is the current experience in VS):
image

However, both VS and VS Code are missing using the keyword in the list. The reason we're not getting the keyword is because we're trying to get completions at __o = [||], which is not a valid location for a using statement.

End result after both of these fixes (1 & 2):
image

@allisonchou allisonchou requested review from a team as code owners September 26, 2023 23:48
const line = razorDocument.lineAt(hostDocumentPosition.line);
const lineText = line.text.substring(0, hostDocumentPosition.character);
if (
lineText.endsWith('@') ||
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this check looks terrible - honestly it makes me cringe too 😅 If anyone has suggestions for an alternative, feel free to suggest

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works but... ugh...

What's the benefit of having a using snippet? Can we just make a server fix for Razor to add it's own completion for @ directives? I think we already do have some... (like @co)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the benefit of having a using snippet? Can we just make a server fix for Razor to add it's own completion for @ directives? I think we already do have some...

I'm guessing a using snippet might be beneficial in the case where the user is already in a C# context and would want to insert something like using () { }?

I've filed dotnet/razor#9330 to track a (still hacky) server-side fix that we can use in both VS and VS Code. In the interest of getting a temporary fix in I'm planning on merging this version for now, but will follow up soon on the server-side fix.

Copy link
Member

@dibarbet dibarbet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only signing off on the roslyn-ide changes (l10n)

Comment on lines +304 to +310
lineText.endsWith('@') ||
lineText.endsWith(
'@u' ||
lineText.endsWith('@us') ||
lineText.endsWith('@usi') ||
lineText.endsWith('@usin') ||
lineText.endsWith('@using')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may have come up with the best way. If the user has already finished typing @using, does the item still need to be added?

Suggested change
lineText.endsWith('@') ||
lineText.endsWith(
'@u' ||
lineText.endsWith('@us') ||
lineText.endsWith('@usi') ||
lineText.endsWith('@usin') ||
lineText.endsWith('@using')
lineText.endsWith('@') ||
lineText.endsWith('@u') ||
lineText.endsWith('@us') ||
lineText.endsWith('@usi') ||
lineText.endsWith('@usin') ||
lineText.endsWith('@using')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered this initially but wanted to match C#'s behavior. They seem to provide the completion item even if the user has finished typing out the whole word:
image

Copy link
Contributor

@ryzngard ryzngard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm approving, and feel gross with you.

@genlu
Copy link
Member

genlu commented Sep 27, 2023

We technically have the same bug in VS, but since we have snippets available there

@allisonchou Sounds like this would be an issue if snippet is disabled? Have you considered adding a specific completion provider in razor instead? That should cover both VS and VSCode

@allisonchou
Copy link
Contributor Author

@allisonchou Sounds like this would be an issue if snippet is disabled?

Yeah, it would be an issue in VS if snippets were disabled.

Have you considered adding a specific completion provider in razor instead? That should cover both VS and VSCode

That's a good idea! I've filed dotnet/razor#9330 and dotnet/razor#9331 as follow ups. I'm going to merge this version for now and then revisit your suggestion soon in the near future in the interest of at least getting some sort of temporary fix in.

@allisonchou allisonchou merged commit a270be4 into dotnet:main Sep 27, 2023
8 checks passed
@allisonchou allisonchou deleted the dev/allichou/FixRazorCompletion branch September 27, 2023 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Linux/Mac] Can't get the intellisense for @using on Blazor App
5 participants